<?php

namespace app\helpers;

use think\exception\ValidateException;
use think\facade\Env;
use think\facade\Filesystem;

trait FileUpdate
{
    /**
     * @param $file
     * @param $folder
     * @return array
     * 保存图片
     */
    public function save($file, $folder)
    {
        $saveName = Filesystem::disk('public')->putFile($folder, $file);
        $path = str_replace('\\', '/', $saveName);

        return [
            'path' => Env::get('domain.http', 'domain.default_http') . ':' . Env::get('domain.post', '998') . '/storage/' . $path
        ];
    }

    /**
     * Notes:
     * User: liuhailong
     * DateTime: 2022/2/11 16:01
     * @param $file
     * @param $folder
     * @return array
     * 获取exif
     */
    public function saveExif($file, $folder)
    {
        $saveName = Filesystem::disk('public')->putFile($folder, $file);
        $path = str_replace('\\', '/', $saveName);
        $url = Env::get('domain.http', 'domain.default_http') . ':' . Env::get('domain.post', '998') . '/storage/' . $path;
//        $exif_arr = exif_read_data($file,0,true);
        return [
//            'DateTimeOriginal' => $exif_arr['FILE']['FileDateTime'] ?? 'mei', //不转义
            'DateTimeOriginal' => date('Y-m-d H:i:s'), //不转义
            'path' => $url
        ];
    }

}